package cn.wolfcode.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public abstract class JwtUtils {
    private static String signkey="wolfcode";
    private static Long expire=24*3600*1000L;
    /**
     * 生成JWT令牌
     */
    public static String gernerateJWT(Map<String,Object> claims){
        String jwt = Jwts.builder()
                .addClaims(claims)
                .signWith(SignatureAlgorithm.HS256, signkey)
                .setExpiration(new Date(System.currentTimeMillis() + expire))
                .compact();
        return jwt;
    }
    /**
     * 解析JWT 令牌
     */
    public static Claims parseJWT(String jwt){
        Claims body = Jwts.parser()
                .setSigningKey(signkey)
                .parseClaimsJws(jwt)
                .getBody();
        return body;
    }
}
